package com.tr.rentcar.controller.home;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSONArray;
import com.tr.rentcar.model.bean.Employee;
import com.tr.rentcar.model.dao.EmployeeDao;

/**
 * Servlet 选择司机姓名，根据id查找司机改变页面值
 */
@WebServlet("/changedriver")
public class ChangeDriverController extends HttpServlet {
	private static final long serialVersionUID = 1L;
	EmployeeDao ed=new EmployeeDao();
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		PrintWriter out = response.getWriter();
		String id = request.getParameter("eid");
		Integer eid=Integer.parseInt(id);
		Employee emp;
		try {
			emp = ed.findById(eid);
			//这个是一个emp对象，转换成json的字符串
			out.print(JSONArray.toJSONString(emp));
			out.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

}
